class Solution(object):
    def minSwaps(self, data):
        """
        :type data: List[int]
        :rtype: int
        """
        n = len(data)
        k = sum(data)
        if k <= 1 or k == n:
            return 0
        max_count = sum(data[:k])
        now_count = max_count
        for i in range(n - k):
            now_count = now_count + data[i + k] - data[i]
            max_count = max(max_count, now_count)
        return k - max_count


s = Solution()
data = [1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1]
print(s.minSwaps(data))
data = [1, 0, 1, 0, 1]
print(s.minSwaps(data))
data = [0, 0, 0, 1, 0]
print(s.minSwaps(data))
data = [1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1]
print(s.minSwaps(data))
